% AMTH 358 Final - Question 2
% FFT based Circular Convolution
%--------------------------------------------------------------------------------

function [c] = fft_cconv(a,b)
  if nargin <2  % print help usage message to console
    usage();
    c = [];
    return;
  end
  
  inverse=1;
  forward=0;
  no_strict=0;
  no_debug = 0;
  
  a_len = length(a);
  b_len = length(b);

  if a_len ~= b_len
    disp('Error: input vectors a and b must have the same length');
    c = [NaN];  % return an invalid data vector
    return;
  end

  af = fft_r2dt(a,forward,no_debug,no_strict);
  bf = fft_r2dt(b,forward,no_debug,no_strict);  
  
%  af = fft(a); bf=fft(b);  % for testing
  
  cf = af .* bf;
 c = fft_r2dt(cf,inverse,no_debug,no_strict);

%  c = ifft(cf); % for testing
  
function usage()
  disp('Usage: fft_cconv <vector a> <vector b>');
  disp('       Vectors a and b must have equal length');
  
  
